import request from '@/utils/request'

export function getServiceArray (params) {
  var data = fromData(params)
  return request({
    url: '/service/getServiceArray',
    method: 'post',
    data
  })
}

export function getServiceInfo (params) {
  var data = fromData(params)
  return request({
    url: '/service/getServiceInfo',
    method: 'post',
    data
  })
}

export function getServiceReArray (params) {
  var data = fromData(params)
  return request({
    url: '/service/getServiceReArray',
    method: 'post',
    data
  })
}

export function addServiceData (params) {
  var data = fromData(params)
  return request({
    url: '/service/addService',
    method: 'post',
    data
  })
}

export function editServiceData (params) {
  var data = fromData(params)
  return request({
    url: '/service/editService',
    method: 'post',
    data
  })
}

export function delServiceData (params) {
  var data = fromData(params)
  return request({
    url: '/service/del_service',
    method: 'post',
    data
  })
}

// 服务--获取服务对象ICMPV6列表
export function getServiceIcmpv6 (params) {
  var data = fromData(params)
  return request({
    url: '/service/getServiceIcmpv6',
    method: 'post',
    data
  })
}

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
